Skip to content

feat: add volume flat amount ui#868

Open
charlietlamb wants to merge 4 commits intodevfrom
volume-flat-amount-ui
Open

feat: add volume flat amount ui#868
charlietlamb wants to merge 4 commits intodevfrom
volume-flat-amount-ui

Conversation

@charlietlamb
Copy link
Contributor

@charlietlamb charlietlamb commented Mar 3, 2026

Screenshot 2026-03-03 at 12 44 24

Greptile Summary

This PR adds a volume flat amount UI for volume-based, multi-tier feature pricing. Users can now toggle between a per-unit (amount) view and a flat amount (flat_amount) view via a new segmented control that appears alongside the existing tier-behavior selector. The feature is backed by a new cleanTiersForMode utility that zeroes out unused fields before commit, and is well-covered by a new test file.

Key changes:

  • Improvements — Extracts tier-behavior Select into a new PriceSectionTitle component and adds a Per Unit / Flat Amount IconCheckbox toggle that is only shown for volume-based, multi-tier items.
  • Improvements — Extends PriceTiers to accept a volumePricingMode prop, switching the editable field between amount and flat_amount and hiding the BillingUnits label in flat mode.
  • Improvements — Adds a cleanTiersForMode utility in tierUtils.ts and a handleBeforeCommit hook in EditPlanFeatureSheet to ensure stale field values are zeroed/nulled before the item is committed.
  • Improvements — Adds an optional onBeforeCommit callback to SheetFooterActions that is invoked synchronously before handleUpdateProductItem, preserving the existing commit flow.
  • Improvements — Introduces comprehensive unit tests for cleanTiersForMode and updateTier (flat_amount path) in tierUtils.test.ts.

Two critical issues in EditPlanFeatureSheet should be addressed before merging:

  1. Stale flat_amount when reducing tiers to one in flat mode — If a user edits a multi-tier volume-based item in flat mode and then removes tiers down to one, the handleBeforeCommit guard condition skips cleanup. The single-tier item is submitted with leftover flat_amount values that contradict the per-unit UI state shown to the user.

  2. volumePricingMode state doesn't reset when switching items — The useState lazy initializer runs only once per mount. If users edit item A (with flat pricing) then switch to item B (without flat pricing) without closing the sheet, the toggle state remains frozen at item A's value, causing incorrect UI state for item B.

Confidence Score: 2/5

  • Not safe to merge — two critical state management bugs in EditPlanFeatureSheet will silently produce incorrect backend data in specific user workflows.
  • The core utility logic (cleanTiersForMode, updateTier) is correct and well-tested. UI components are cleanly structured. However, EditPlanFeatureSheet has two critical bugs: (1) handleBeforeCommit skips cleanup when users reduce a multi-tier volume item to single-tier in flat mode, leaving stale flat_amount in the submitted data; (2) volumePricingMode state won't reset when switching between items without remounting, causing incorrect toggle state. Both bugs lead to silent data corruption and should be fixed before shipping.
  • vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx — requires fixes to handleBeforeCommit guard condition and volumePricingMode state initialization.

Sequence Diagram

sequenceDiagram
    participant User
    participant PriceSectionTitle
    participant EditPlanFeatureSheet
    participant PriceTiers
    participant SheetFooterActions
    participant tierUtils

    User->>PriceSectionTitle: Select "Volume-based" tier behavior
    PriceSectionTitle->>EditPlanFeatureSheet: onTierBehaviorChange("VolumeBased")
    EditPlanFeatureSheet->>EditPlanFeatureSheet: setItem({ tier_behavior: VolumeBased })
    Note over EditPlanFeatureSheet: showVolumePricingToggle = true<br/>(isVolumeBased && isMultiTier)

    User->>PriceSectionTitle: Click "Flat Amount" toggle
    PriceSectionTitle->>EditPlanFeatureSheet: onVolumePricingModeChange("flat")
    EditPlanFeatureSheet->>EditPlanFeatureSheet: setVolumePricingMode("flat")
    EditPlanFeatureSheet->>PriceTiers: volumePricingMode="flat"
    PriceTiers->>User: Shows flat_amount field (hides BillingUnits)

    User->>PriceTiers: Enter flat amount value
    PriceTiers->>tierUtils: updateTier({ field: "flat_amount", value })
    tierUtils->>EditPlanFeatureSheet: setItem(updatedItem)

    User->>SheetFooterActions: Click "Update Plan Feature"
    SheetFooterActions->>EditPlanFeatureSheet: onBeforeCommit()
    EditPlanFeatureSheet->>tierUtils: cleanTiersForMode({ item, mode: "flat" })
    tierUtils-->>EditPlanFeatureSheet: cleaned item (amount=0 preserved)
    EditPlanFeatureSheet->>EditPlanFeatureSheet: setItem(cleaned)
    SheetFooterActions->>SheetFooterActions: handleUpdateProductItem()
    Note over SheetFooterActions: commitItemDraft() or closeSheet()

    User->>PriceSectionTitle: Select "Graduated" tier behavior
    PriceSectionTitle->>EditPlanFeatureSheet: onTierBehaviorChange("Graduated")
    EditPlanFeatureSheet->>EditPlanFeatureSheet: setVolumePricingMode("per_unit")
    EditPlanFeatureSheet->>EditPlanFeatureSheet: clear flat_amount on all tiers
    EditPlanFeatureSheet->>EditPlanFeatureSheet: setItem(newItem)
Loading

Last reviewed commit: c62fc87

Context used:

  • Rule from dashboard - CLAUDE.md (source)

@vercel
Copy link

vercel bot commented Mar 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
autumn-vite Ready Ready Preview, Comment Mar 4, 2026 11:11am

Request Review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@charlietlamb
Copy link
Contributor Author

@cubic-dev-ai review

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 4, 2026

@cubic-dev-ai review

@charlietlamb I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Confidence score: 3/5

  • There is a concrete regression risk in vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx: volume pricing mode inference treats flat_amount: 0 as falsy, so valid zero-value flat pricing may initialize to the wrong mode.
  • Given the issue’s high severity/confidence (7/10, 9/10) and direct user-facing behavior impact in pricing setup, this carries moderate merge risk until corrected.
  • Pay close attention to vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx - mode inference logic should recognize zero flat amounts as valid flat mode inputs.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx">

<violation number="1" location="vite/src/views/products/plan/components/edit-plan-feature/EditPlanFeatureSheet.tsx:46">
P1: Volume pricing mode inference is incorrect for valid zero flat amounts; `flat_amount: 0` should still initialize flat mode.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@charlietlamb
Copy link
Contributor Author

@cubic-dev-ai review

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 4, 2026

@cubic-dev-ai review

@charlietlamb I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Confidence score: 2/5

  • There is a high-confidence race condition in vite/src/views/products/plan/components/edit-plan-feature/SheetFooterActions.tsx: onBeforeCommit is called without await, so cleanup can overlap with handleUpdateProductItem and commit stale item data.
  • Because this affects commit ordering in a save/update flow, the user-facing regression risk is significant until the async sequencing is fixed.
  • Pay close attention to vite/src/views/products/plan/components/edit-plan-feature/SheetFooterActions.tsx - ensure pre-commit work is awaited before updating or committing product item state.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="vite/src/views/products/plan/components/edit-plan-feature/SheetFooterActions.tsx">

<violation number="1" location="vite/src/views/products/plan/components/edit-plan-feature/SheetFooterActions.tsx:24">
P1: `onBeforeCommit` is invoked without awaiting completion, so pre-commit cleanup can race with `handleUpdateProductItem` and commit stale item data.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant